$(function () {
    //获取产地
    var cdOptions = [];
    $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm': 'cd'}, function (data) {
        cdOptions = data;
    });
    //获取计重方式
    var jzfsOptions = [];
    $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm': 'jzfs'}, function (data) {
        jzfsOptions = data;
    });
    var _xy_rzlx = $.parseJSON($("#wzjhgl_content_xy_rzlx").val());
    var _wzjh_zggsId = $("#wzjhgl_content_wzjh_zggsId").val();

//===============自购表单===================
    var zgwzjhXyOptions = {
        queryParams: {
            "types[0]": "cgxy",
            "types[1]": "sfxy",
            "ssgsId": _wzjh_zggsId,
            "spzt": "ysp"
        },
        onSelect: function (rowIndex, rowData) {
            initGrid(rowData);
        }
    };

    var tpwzjhXyOptions = {
        queryParams: {
            "types[0]": "cgxy",
            "tplx": "false",
            //"ssgsId": $("#wzjhglForm [name='tpwzjh.sbgs.id']").val(),
            "spzt": "ysp"
        },
        onSelect: function (rowIndex, rowData) {
            $("#wzjhglForm [name='tpwzjh.gys.qc']").val(rowData.gys_qc);
            $("#wzjhglForm [name='tpwzjh.gys.id']").val(rowData.gys_id);
            $("#wzjhglForm [name='tpwzjh.tcgs.qc']").val(rowData.tcgs_qc);
            $("#wzjhglForm [name='tpwzjh.tcgs.id']").val(rowData.tcgs_id);
            $("#wzjhglForm [name='tpwzjh.tcbm.qc']").val(rowData.tcbm_qc);
            $("#wzjhglForm [name='tpwzjh.tcbm.id']").val(rowData.tcbm_id);
            $("#wzjhglForm [name='tpwzjh.tcfs.z']").val(rowData.tcfs_z);
            $("#wzjhglForm [name='tpwzjh.tcfs.id']").val(rowData.tcfs_id);
        }
    };

    var ljOptions = {
        editable: false,
        onSelect: function (record) {
            initLjGrid(record);
        }
    };
    var gysCombobox = $("#wzjhglForm :text[name='zgwzjh.gys.id']").combobox({valueField: 'id', textField: 'qc'});
    var khCombobox = $("#wzjhglForm :text[name='zgwzjh.kh.id']").combobox({valueField: 'id', textField: 'qc'});
    var dbfCombobox = $("#wzjhglForm :text[name='zgwzjh.dbf.id']").combobox({valueField: 'id', textField: 'qc'});
    var ljCombobox = $("#wzjhglForm :text[name='zgwzjh.lj.id']").combobox({valueField: 'id', textField: 'mc'});
    var zgwzjhXyCombogrid = $("#wzjhglForm :text[name='zgwzjh.xy.id']").combogrid();
    $(zgwzjhXyCombogrid).xyCombogrid(zgwzjhXyOptions);
    //统配协议表单
    var tpwzjhXyCombogrid = $("#wzjhglForm :text[name='tpwzjh.xy.id']").combogrid();
    $(tpwzjhXyCombogrid).xyCombogrid(tpwzjhXyOptions);
    var rzlxCombobox = $("#wzjhglForm :text[name='zgwzjh.rzlx']").combobox({valueField: 'code', textField: 'mc', data: [
        {code: 'DDH', mc: '代订货'},
        {code: 'SMY', mc: '商贸银' },
        {code: 'BDC', mc: '保兑仓' }
    ]});
    var lrblNumberbox = $("#wzjhglForm [name='zgwzjh.lrbl']").numberbox({required: true, precision: 4, min: 0, max: 100, decimalSeparator: '.'});


    $("#zgwzjh_zbcg").click(function () {
        if ($(this).attr("checked") != undefined && $(this).attr("checked") == "checked") {
            //TO-DO 赋值公司本部
            $("#zgwzjh_cggs_jc").val("积微物联");
            $("#zgwzjh_cggs_id").val(1);
        } else {
            $("#zgwzjh_cggs_jc").val($("#zgwzjh_sbgs_jc").val());
            $("#zgwzjh_cggs_id").val($("#zgwzjh_sbgs_id").val());
        }
    })


//===========================
//========物资计划明细表头=======
//===========================
//自购物资计划表体
    var zgwzjhmxCol = [
        [
            {field: 'checked', checkbox: true},
            {title: '物资编码', field: 'wzgg.code', editor: {type: 'validatebox', options: {required: true}}, width: 150},
            {title: '物资名称', field: 'wzgg.name', editor: {type: 'validatebox', options: {required: true}}, width: 150},
            {title: '规格型号', field: 'ggxh', editor: {type: 'text'}, width: 150},
            {title: '单位', field: 'wzgg.dw', editor: {type: 'validatebox', options: {required: true}}, width: 75},
            {title: '产地', field: 'cd.id', editor: {type: 'combobox', options: {valueField: 'id', textField: 'z'}},
                formatter: function (value, row, index) {
                    for (var i = 0; i < cdOptions.length; i++) {
                        if (cdOptions[i].id == value) return cdOptions[i].z;
                    }
                    return value;
                },
                width: 150},
            {title: '计划数量', field: 'sbsl', editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 4}},
                formatter:function(value){
                    var sl = formatSl(value,",");
                    return sl;
                }, width: 150}
        ]
    ];
//统配物资计划
    var tpwzjhmxCol = [
        [
            {field: 'checked', checkbox: true, title: "选择"},
            {title: '物资编码', field: 'wzgg.code', editor: {type: 'validatebox', options: {required: true}}, width: 70},
            {title: '物资名称', field: 'wzgg.name', editor: {type: 'validatebox', readonly: true, options: {required: true}}, width: 70},
            {title: '规格型号', field: 'ggxh', editor: {type: 'text'}, width: 70},
            {title: '单位', field: 'wzgg.dw', editor: {type: 'validatebox', options: {required: true}}, width: 35},
            {title: '产地', field: 'cd.id', editor: {type: 'combobox', options: {valueField: 'id', textField: 'z'}},
                formatter: function (value, row, index) {
                    for (var i = 0; i < cdOptions.length; i++) {
                        if (cdOptions[i].id == value) return cdOptions[i].z;
                    }
                    return value;
                },
                width: 70},
            {title: '记重方式', field: 'jzfs.id', editor: {type: 'combobox', options: {valueField: 'id', textField: 'z'}},
                formatter: function (value, row, index) {
                    for (var i = 0; i < jzfsOptions.length; i++) {
                        if (jzfsOptions[i].id == value) return jzfsOptions[i].z;
                    }
                    return value;
                }, width: 70},
            {title: '计划数量', field: 'sbsl', editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 4}},
                formatter:function(value){
                    var sl = formatSl(value,",");
                    return sl;
                },  width: 70},
            {title: '备注', field: 'bz', editor: {type: 'text'}, width: 70}
        ]
    ];

    var grid = null;

//    $.extend(zgwzjhXyOptions, {required: true});
//    $("#wzjhglForm :text[name='zgwzjh.xy.id']").xyCombogrid(zgwzjhXyOptions);
//===========================
//========物资计划类型选择=======
//===========================

//物资计划类型控制表单显示
    $("#wzjhglForm [name='type']").click(function () {
        var options = {
            toolbar: '#wzjhgl_wzjhmx_toolbar',
            fitColumns: true,
            fit: true,
            checkbox: true,
            checkOnSelect: false,
            selectOnCheck: false,
            rownumbers: true,
            showFooter: true,
            onClickRow: function (rowIndex, rowData) {
                datagridOnSelectHandle(rowIndex, rowData);
            },
            onDestroy: function () {
                countSum();
            }
        };

        if ($(this).val() == "XyZgwzjh") {
            $("#wzjhglForm tr[name='zgwzjh']").show();
            $("#wzjhglForm tr[name='tpwzjh']").hide();
            $("#wzjhglForm tr[name='zgwzjh']:eq(1)").show();
            $(gysCombobox).combobox("clear");
            $(khCombobox).combobox("clear");
            $(dbfCombobox).combobox("clear");

            $(ljCombobox).combobox("clear");
            $(rzlxCombobox).combobox("clear");

            $(rzlxCombobox).combobox("loadData", [
                {code: 'DDH', mc: '代订货'},
                {code: 'SMY', mc: '商贸银' },
                {code: 'BDC', mc: '保兑仓' }
            ]);

           // $.extend(zgwzjhXyOptions, {required: true});
            $(zgwzjhXyCombogrid).combogrid({required:true});


            $(ljCombobox).combobox({required: false, valueField: 'id', textField: 'mc'});
            $(dbfCombobox).combobox("disable");

            //$.extend(tpwzjhXyOptions, {required: false});
            $(tpwzjhXyCombogrid).combogrid({required:false});

            $(zgwzjhXyCombogrid).combogrid("clear");
            $(tpwzjhXyCombogrid).combogrid("clear");
            //自购利率
            $(lrblNumberbox).numberbox({required: true});
            $(lrblNumberbox).numberbox('clear');

            $(rzlxCombobox).combobox({required: false});
            //物资计划明细编辑列表
            $.extend(options, {columns: zgwzjhmxCol});
            //修改加载from数据和物资计划明细数据
            if ($("#wzjhgl_content_cgwzjh_id").val() != "") {
                $.extend(options, {url: $.webPath() + '/jhgl/wzjhgl/wzjhmxList?type=Zgwzjh&id=' + $("#wzjhgl_content_cgwzjh_id").val()});
            }
            grid = $('#wzjhgl_wzjhmx_edatagrid').edatagrid(options);
            addFooter(0, $(this).val());
        } else if ($(this).val() == "LjZgwzjh") {
            $("#wzjhglForm tr[name='zgwzjh']").show();
            $("#wzjhglForm tr[name='tpwzjh']").hide();
            $("#wzjhglForm tr[name='zgwzjh']:eq(1)").hide();
            $(gysCombobox).combobox("clear");
            $(khCombobox).combobox("clear");
            $(dbfCombobox).combobox("clear");

            $(ljCombobox).combobox("clear");
            $(rzlxCombobox).combobox("clear");

            $(rzlxCombobox).combobox("loadData", [
                {code: 'DDH', mc: '代订货'},
                {code: 'SMY', mc: '商贸银' },
                {code: 'BDC', mc: '保兑仓' }
            ]);

           // $.extend(zgwzjhXyOptions, {required: false});
           // $(zgwzjhXyCombogrid).xyCombogrid(zgwzjhXyOptions);
            $(zgwzjhXyCombogrid).combogrid({required:false});

            $.extend(ljOptions, {required: true});
            $(ljCombobox).ljcombobox(_wzjh_zggsId, "0,1", ljOptions);
            $(dbfCombobox).combobox("enable");


            //自购利率
            $(lrblNumberbox).numberbox({required: true});
            $(lrblNumberbox).numberbox('clear');
            //去除统配物资计划协议校验
           // $.extend(tpwzjhXyOptions, {required: false});
           // $(tpwzjhXyCombogrid).xyCombogrid(tpwzjhXyOptions);
            $(tpwzjhXyCombogrid).combogrid({required:false});


            $(zgwzjhXyCombogrid).combogrid("clear");
            $(tpwzjhXyCombogrid).combogrid("clear");

            $(rzlxCombobox).combobox({required: false});
            //物资计划明细编辑列表
            $.extend(options, {columns: zgwzjhmxCol});
            //修改加载from数据和物资计划明细数据
            if ($("#wzjhgl_content_cgwzjh_id").val() != "") {
                $.extend(options, {url: $.webPath() + '/jhgl/wzjhgl/wzjhmxList?type=Zgwzjh&id=' + $("#wzjhgl_content_cgwzjh_id").val()});
            }
            grid = $('#wzjhgl_wzjhmx_edatagrid').edatagrid(options);
            addFooter(0, $(this).val());
        } else if ($(this).val() == "Tpwzjh") {
            $("#wzjhglForm tr[name='zgwzjh']").hide();
            $("#wzjhglForm tr[name='tpwzjh']").show();


            //去除自购物资计划协议校验
            //$.extend(zgwzjhXyOptions, {required: false});
            //$(zgwzjhXyCombogrid).xyCombogrid(zgwzjhXyOptions);

            $(zgwzjhXyCombogrid).combogrid({required:false});

            $(rzlxCombobox).combobox("loadData", [
                {code: 'DDH', mc: '代订货'},
                {code: 'SMY', mc: '商贸银' },
                {code: 'BDC', mc: '保兑仓' }
            ]);

            //去除自购物资计划路径校验
            $(ljCombobox).combobox({required: false, valueField: 'id', textField: 'mc'});

            //添加统配物资计划协议校验
           //$.extend(tpwzjhXyOptions, {required: true});
            var tpwzjhXyOptions2 = {
                required:true,
                queryParams: {
                    "types[0]": "cgxy",
                    "tplx": "false",
                    "tcgs":"false",
                    "spzt": "ysp"
                },
                onSelect: function (rowIndex, rowData) {
                    $("#wzjhglForm [name='tpwzjh.gys.qc']").val(rowData.gys_qc);
                    $("#wzjhglForm [name='tpwzjh.gys.id']").val(rowData.gys_id);
                    $("#wzjhglForm [name='tpwzjh.tcgs.qc']").val(rowData.tcgs_qc);
                    $("#wzjhglForm [name='tpwzjh.tcgs.id']").val(rowData.tcgs_id);
                    $("#wzjhglForm [name='tpwzjh.tcbm.qc']").val(rowData.tcbm_qc);
                    $("#wzjhglForm [name='tpwzjh.tcbm.id']").val(rowData.tcbm_id);
                    $("#wzjhglForm [name='tpwzjh.tcfs.z']").val(rowData.tcfs_z);
                    $("#wzjhglForm [name='tpwzjh.tcfs.id']").val(rowData.tcfs_id);
                }
            };
           $(tpwzjhXyCombogrid).xyCombogrid(tpwzjhXyOptions2);

            $(zgwzjhXyCombogrid).combogrid("clear");
            $(tpwzjhXyCombogrid).combogrid("clear");
            //自购利率
            $(lrblNumberbox).numberbox({required: false});
            $(lrblNumberbox).numberbox('clear');

            $(rzlxCombobox).combobox({required: false});
            //物资计划明细编辑列表
            $.extend(options, {columns: tpwzjhmxCol});
            if ($("#wzjhgl_content_cgwzjh_id").val() != "") {
                $.extend(options, {url: $.webPath() + '/jhgl/wzjhgl/wzjhmxList?type=Tpwzjh&id=' + $("#wzjhgl_content_cgwzjh_id").val()});
            }
            grid = $('#wzjhgl_wzjhmx_edatagrid').edatagrid(options);
            addFooter(0, $(this).val());
        }
    });

//默认选中自购物资计划类型
    var checkedRadio = $("#wzjhglForm [name='type']:checked");
    if (checkedRadio.length == 0) {
        $("#wzjhglForm [name='type']:first").click();
    } else {
        $(checkedRadio).click();
        $("#wzjhglForm [name='type']").attr("disabled", "true");
    }

//===========================
//========物资计划明细页面========
//===========================
//新增物资计划明细
    $("#wzjhgl_wzjhmx_toolbar [name='xzwzmx']").click(function () {
        searchcodewindow(openSearchWindowOKbtnHandle);
    });
//删除物资计划明细
    $("#wzjhgl_wzjhmx_toolbar [name='scwzmx']").click(function () {
        var rows = $(grid).edatagrid('getChecked');
        if (rows) {
            $.messager.confirm('提示', '是否确定删除物资明细?', function (r) {
                if (r) {
                    $.each(rows, function (i, val) {
                        var index = $(grid).edatagrid('getRowIndex', val);
                        $(grid).edatagrid('deleteRow', index);
                    });
                }
            });
        }
        $(grid).edatagrid('resize');
    });

//批量维护物资明细中的产地
    $("#wzjhgl_wzjhmx_toolbar [name='plwhcd']").click(function () {
        $(grid).edatagrid('saveRow');
        var rows = $(grid).edatagrid('getRows');
        var yx = $.grep(rows, function (v, i) {
            return v['cd.id'] && v['cd.id'] != '';
        });
        if (yx.length > 0) {
            for (var i = 0; i < rows.length; i++) {
                if (!(rows[i]['cd.id'] && rows[i]['cd.id'] != '')) {
                    rows[i]['cd.id'] = yx[0]['cd.id'];
                }
            }
            $(grid).edatagrid('loadData', {total: rows.length, rows: rows});
        }
    });

//表格处在编辑状态的时候，给表单绑定事件
    function datagridOnSelectHandle(rowIndex, rowData) {
        //获取每个单元格
        $(grid).edatagrid('editRow', rowIndex);
        var editors = $(grid).datagrid('getEditors', rowIndex);
        if (editors.length == 0)
            return;
        var bmEditor = editors[0]; // 物资编码编辑框
        $(bmEditor.target).attr("readonly", "true");
        var pmEditor = editors[1]; //物资名称编辑框
        $(pmEditor.target).attr("readonly", "true");
        var ggEditor = editors[2];// 规格编辑框
//        $(ggEditor.target).attr("readonly", "true");
        var cdEditor = editors[4];// 产地编辑框
        $(cdEditor.target).combobox("loadData", cdOptions);
        var sbslEditor = null;//申报数量编辑框
        if (editors.length == 6)
            sbslEditor = editors[5];
        else {
            sbslEditor = editors[6];
            var jzfsEditor = editors[5];// 计重方式编辑框
            $(jzfsEditor.target).combobox("loadData", jzfsOptions);
            if (jzfsOptions != null && jzfsOptions.length != 0)
                $(jzfsEditor.target).combobox("select", jzfsOptions[0].id);
        }
        //绑定事件
        //弹出物资编码树
        bmEditor.target.unbind("dblclick").bind('dblclick', function () {
            searchcodewindow(openSearchWindowOKbtnHandle);
        });
        //弹出物资编码树
        pmEditor.target.unbind("dblclick").bind('dblclick', function () {
            searchcodewindow(openSearchWindowOKbtnHandle);
        });
        //弹出物资编码树
        ggEditor.target.unbind("dblclick").bind("dblclick", function () {
            searchcodewindow(openSearchWindowOKbtnHandle);
        });
        //计算总量
        sbslEditor.target.unbind("change").bind("change", function () {
            var temp = parseFloat($(this).val()).toFixed(4);
            temp = isNaN(temp) ? 0 : temp;
            var sum = 0;
            var data = $(grid).edatagrid("getData");
            for (var i = 0; i < data.rows.length; i++) {
                if (i == rowIndex)
                    sum += parseFloat(temp);
                else {
                    var t = parseFloat(data.rows[i]['sbsl']);
                    t = isNaN(t) ? 0 : t;
                    sum += t;
                }
            }
            addFooter(sum.toFixed(4));
        });
    }

//查询物资代码确定按钮回调函数
    function openSearchWindowOKbtnHandle(data) {
        var type = $("#wzjhglForm [name='type']:checked").val();
        var rowdatas = $.map(data, function (n, i) {
            var temp = null;
            if (type == 'XyZgwzjh' || type == 'LjZgwzjh')
                temp = {
                    'wzgg.id': n.id,
                    'wzgg.code': n.code,
                    'wzgg.name': n.name,
                    'ggxh': n.ggxh,
                    'wzgg.dw': n.dw,
                    'cd.id': null,
                    'sbsl': 0
                };
            if (type == 'Tpwzjh')
                temp = {
                    'wzgg.id': n.id,
                    'wzgg.code': n.code,
                    'wzgg.name': n.name,
                    'ggxh': n.ggxh,
                    'wzgg.dw': n.dw,
                    'cd.id': null,
                    'ck': '',
                    'jzfs.id': null,
                    'bz': '',
                    'sbsl': 0
                };
            return temp;
        });
        $.each(rowdatas, function () {
            $(grid).edatagrid('appendRow', this);
        });
        countSum();
    }

//计算计划总量
    function countSum() {
        var sum = 0;
        var data = $(grid).edatagrid("getData");
        for (var i = 0; i < data.rows.length; i++) {
            var temp = parseFloat(data.rows[i]['sbsl']);
            temp = isNaN(temp) ? 0 : temp;
            sum += temp;
        }
        addFooter(sum.toFixed(4));
    }

    function addFooter(sum, t) {
        var type = t;
        if (typeof type == "undefined")
            type = $("#wzjhglForm [name='type']:checked").val();
        var footer = null;
        if (type == 'XyZgwzjh' || type == 'LjZgwzjh')
            footer = {"cd.id": "合计", "sbsl": sum};
        if (type == 'Tpwzjh')
            footer = {"jzfs.id": "合计", "sbsl": sum};
        if (footer != null)
            $(grid).datagrid('reloadFooter', [footer]);
    }

    function initGrid(rowData) {
        var sydata = [];
        var xydata = [];
        //可修改
        $.post($.webPath() + '/organ/ljwh/ljinfosxy', {'ljId': rowData.lj_id}, function (data) {
            $(data).each(function (i, item) {
                if (item.lx == 'sy') {
                    sydata.push(item);
                } else {
                    xydata.push(item);
                }
            });
            //供应商
            $(gysCombobox).combobox("clear");
            if (rowData.gys_id) {
                $(gysCombobox).combobox("loadData", [
                    {id: rowData.gys_id, qc: rowData.gys_qc}
                ]);
                $(gysCombobox).combobox("setValue", rowData.gys_id);
            } else {
                $(gysCombobox).combobox("loadData", sydata);
                if (sydata.length != 0)
                    $(gysCombobox).combobox("setValue", sydata[0].id);
            }
            //客户
            $(khCombobox).combobox("clear");
            if (rowData.kh_id) {
                $(khCombobox).combobox("loadData", [
                    {id: rowData.kh_id, qc: rowData.kh_qc}
                ]);
                $(khCombobox).combobox("setValue", rowData.kh_id);
            } else {
                $(khCombobox).combobox("loadData", xydata);
                if (xydata.length != 0)
                    $(khCombobox).combobox("setValue", xydata[0].id);
            }
        });

        //担保方
        $(dbfCombobox).combobox("clear");
        $(dbfCombobox).combobox("loadData", [
            {id: rowData.dbf_id, qc: rowData.dbf_qc}
        ]);
        $(dbfCombobox).combobox("setValue", rowData.dbf_id);
        //路径
        $(ljCombobox).combobox("clear");
        $(ljCombobox).combobox("loadData", [
            {id: rowData.lj_id, mc: rowData.lj_mc}
        ]);
        $(ljCombobox).combobox("setValue", rowData.lj_id);
        //融资类型
        $(rzlxCombobox).combobox("clear");
        var rzlxData = [];
        var rzlxCode = null;
        if (typeof rowData.rzlx != "undefined") {
            rzlxData = [_xy_rzlx[rowData.rzlx]];
            rzlxCode = _xy_rzlx[rowData.rzlx].code;
            $(rzlxCombobox).combobox("loadData", rzlxData);
            if (rzlxCode != null)
                $(rzlxCombobox).combobox("setValue", rzlxCode);
        }else{
            $(rzlxCombobox).combobox("loadData", [
                {code: 'DDH', mc: '代订货'},
                {code: 'SMY', mc: '商贸银' },
                {code: 'BDC', mc: '保兑仓' }
            ]);
        }

        //利润比例（利率）---- 综合服务费(%)
        var ll = parseFloat(rowData.lj_ll);
        ll = isNaN(ll) ? 0 : ll;
        $(lrblNumberbox).numberbox("setValue", ll);

        //控制融资类型、利率是否显示
        if (rowData.type == "cgxy") {
            var lenth = $("#wzjhglForm tr[name='zgwzjh']").length;
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 2) + ")").hide();
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 1) + ")").hide();
            $(lrblNumberbox).numberbox({required: false});
        } else {
            var lenth = $("#wzjhglForm tr[name='zgwzjh']").length;
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 2) + ")").show();
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 1) + ")").show();
            $(lrblNumberbox).numberbox({required: true});
        }
    }

    function initLjGrid(record) {
        var sydata = [];
        var xydata = [];
        if (record.lx == 0) {
            var lenth = $("#wzjhglForm tr[name='zgwzjh']").length;
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 2) + ")").show();
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 1) + ")").show();
            $(rzlxCombobox).combobox({required:true});
            $(lrblNumberbox).numberbox({required: true});
        } else {
            var lenth = $("#wzjhglForm tr[name='zgwzjh']").length;
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 2) + ")").hide();
            $("#wzjhglForm tr[name='zgwzjh']:eq(" + (lenth - 1) + ")").hide();
            $(rzlxCombobox).combobox({required: false});
            $(lrblNumberbox).numberbox({required: false});
        }

        var ll = parseFloat(record.ll);
        ll = isNaN(ll) ? 0 : ll;
        $(lrblNumberbox).numberbox("setValue", ll);

        $.post($.webPath() + '/organ/ljwh/ljinfosxy', {'ljId': record.id}, function (data) {
            $(data).each(function (i, item) {
                if (item.lx == 'sy') {
                    sydata.push(item);
                } else {
                    xydata.push(item);
                }
            });
            //供应商
            $(gysCombobox).combobox("clear");
            $(gysCombobox).combobox("loadData", sydata);
            if (sydata.length != 0)
                $(gysCombobox).combobox("setValue", sydata[0].id);
            //客户
            $(khCombobox).combobox("clear");
            $(khCombobox).combobox("loadData", xydata);
            if (xydata.length != 0)
                $(khCombobox).combobox("setValue", xydata[0].id);

        });

        //清空协议
        $(zgwzjhXyCombogrid).combogrid("clear");
    }
})